package s01;

public class Rectangle { //矩形类
	private int width, height;
	
	public void setWidth(int width) { //this只能在实例方法中使用
		this.width = width;
	}

	public void setHeight(int height) {
		this.height = height;
	}
	public int getArea() {
		return width*height;
	}
	public Rectangle() {

	}
	public Rectangle(int width, int height) {
		this.width = width;
		this.height = height;
	}

	public void showMessage() {//实例方法
		System.out.printf("Rectangle(width:%d, height:%d), Area=%d\n", width, height, getArea());
	}
	public static void showMessage(int width, int height) { //静态方法中不能使用this对象
//		(1)不能使用this.getArea()来获取面积
//		System.out.printf("Rectangle(width:%d, height:%d), Area=%d\n", width, height, this.getArea());
		
//		(2)直接用width*height来算面积没有问题，但是若面积计算很复杂时将很不方便
//		System.out.printf("Rectangle(width:%d, height:%d), Area=%d\n", width, height, width*height);
		
//		(3)利用传递的参数来创建对象，利用对象来获取面积
//		Rectangle r = new Rectangle(width, height);
//		System.out.printf("Rectangle(width:%d, height:%d), Area=%d\n", width, height, r.getArea());
		
//		(4)直接利用创建的对象来显示信息
		Rectangle r = new Rectangle(width, height);
		r.showMessage();
	}

	public static void showMessage(Rectangle rectangle) {//显示通过参数指定的矩形对象rectangle的信息
		rectangle.showMessage();
	}
	
	
	
	
	
	
	
	
	
	
	
	
	
	
	
	
}
